""""""
from common.base import Base, open_browser

"""提交订单页面"""

url = "http://ecshop.itsoso.cn/flow.php"


class SubmitOrder_page(Base):
    """制作定位器"""

    """配送方式"""
    st_loc = (
        "css selector", "#shippingTable > tbody > tr:nth-child(2) > td:nth-child(1) > input[type='radio'']")  # 申通快递

    yj_loc = (
        "css selector", "#shippingTable > tbody > tr:nth-child(3) > td:nth-child(1) > input[type='radio']")  # 邮局平邮

    collect_loc = (
        "css selector", "#shippingTable > tbody > tr:nth-child(3) > td:nth-child(1) > input[type='radio']")  # 运费到付

    sf_loc = (
        "css selector", "#shippingTable > tbody > tr:nth-child(3) > td:nth-child(1) > input[type='radio']")  # 顺丰速运

    """支付方式"""
    tg_loc = ("css selector", "# paymentTable > tbody > tr:nth-child(2) > td:nth-child(1)")  # 天宫收行

    alipay_loc = ("css selector", "# alipay ")  # 支付宝支付

    wechat_loc = ("css selector", "# wxpay ")  # 微信支付

    balance_loc = (
        "css selector", "# paymentTable > tbody > tr:nth-child(4) > td:nth-child(1) > input[type='radio'] ")  # 余额支付

    bank_loc = (
        "css selector", "# paymentTable > tbody > tr:nth-child(5) > td:nth-child(1) > input[type='radio']")  # 银行汇款

    """商品包装"""
    unpacked_loc = (
        "css selector", "# packTable > tbody > tr:nth-child(2) > td:nth-child(1) > input[type='radio']")  # 不要包装

    packing_box_loc = (
        "css selector", "# packTable > tbody > tr:nth-child(3) > td:nth-child(1) > input[type='radio']")  # 精品包装

    """祝福贺卡"""
    no_card_loc = (
        "css selector", "# cardTable > tbody > tr:nth-child(2) > td:nth-child(1) > input[type='radio']")  # 不要贺卡

    greeting_card_loc = (
        "css selector", "# cardTable > tbody > tr:nth-child(3) > td:nth-child(1) > input[type='radio']")  # 祝福贺卡

    greeting_loc = (
        "css selector", "# cardTable > tbody > tr:nth-child(4) > td:nth-child(3) > textarea")  # 祝福语

    """其他信息"""
    use_the_balance_loc = ("css selector", "# ECS_SURPLUS")  # 使用余额

    invoice_loc = ("css selector", "# ECS_NEEDINV")  # 开发票

    order_postscript_loc = (
        "css selector",
        "# theForm > div:nth-child(14) >table > tbody > tr:nth-child(4) >td:nth-child(1) > strong")  # 订单附言

    wait_goods_loc = (
        "css selector",
        "# theForm > div:nth-child(14) >table > tbody > tr:nth-child(5) > td:nth-child(2) > label:nth-child(1) > input[type='radio']")  # 缺货处理 - 等待所有商品备齐后再发

    cancell_loc = (
        "css selector",
        "# theForm > div:nth-child(14) >table > tbody > tr:nth-child(5) >td:nth-child(2) > label:nth-child(2) >input[type='radio']")  # 缺货处理 - 取消订单

    negotiate_loc = (
        "css selector",
        "# theForm > div:nth-child(14) > table >tbody > tr:nth-child(5) >td:nth-child(2) > label:nth-child(3) >input[type='radio']")  # 缺货处理 - 与店主协商

    submit_order_loc = (
        'css selector','[src *="bnt_subOrder.gif"]')  # 提交订单

    def click_st(self):
        """
        点击单选框申通快递
        :return:
        """
        self.radio(self.st_loc)

    def click_yj(self):
        """
        点击单选框邮局平邮
        :return:
        """
        self.radio(self.yj_loc)

    def click_collect(self):
        """
        点击单选框运费到付
        :return:
        """
        self.radio(self.collect_loc)

    def click_sf(self):
        """
        点击单选框顺丰速运
        :return:
        """
        self.radio(self.sf_loc)

    def click_wechat(self):
        """
        点击单选微信支付
        :return:
        """
        self.radio(self.wechat_loc)

    def click_alipay(self):
        """
        点击单选框支付宝支付
        :return:
        """
        self.radio(self.alipay_loc)

    def click_balance(self):
        """
        点击单选框余额支付
        :return:
        """
        self.radio(self.balance_loc)

    def click_bank(self):
        """
        点击单选框银行汇款转账
        :return:
        """
        self.radio(self.bank_loc)

    def click_unpacked(self):
        """
        点击单选框不要包装
        :return:
        """
        self.radio(self.unpacked_loc)

    def click_packing_box(self):
        """
        点击单选框精品包装
        :return:
        """
        self.radio(self.packing_box_loc)

    def click_no_card(self):
        """
        点击单选框不要贺卡
        :return:
        """
        self.radio(self.no_card_loc)

    def input_greeting(self, text):
        """
        输入祝福贺卡
        :return:
        """
        self.send_keys(self.greeting_loc, text)

    def input_use_the_balance(self, text):
        """
        输入使用要使用的余额金额
        :return:
        """
        self.send_keys(self.use_the_balance_loc, text)

    def click_invoice(self):
        """
        点击复选框开发票
        :return:
        """
        self.checkbox(self.invoice_loc)

    def input_postscript(self, text):
        """
        输入使用要使用的余额金额
        :return:
        """
        self.send_keys(self.order_postscript_loc, text)

    def click_wait_goods(self):
        """
        点击缺货处理 - 等待所有商品备齐后再发
        :return:
        """
        self.radio(self.wait_goods_loc)

    def click_cancelled_order(self):
        """
        点击缺货处理 -取消订单
        :return:
        """
        self.radio(self.cancell_loc)

    def click_negotiate_seller(self):
        """
        点击 缺货处理 - 与店主协商
        :return:
        """
        self.radio(self.negotiate_loc)

    def click_submit_order(self):
        """
        点击提交订单
        :return:
        """
        self.click(self.submit_order_loc)


if __name__ == '__main__':
    driver=open_browser()
    submit=SubmitOrder_page(driver)
    url='http://ecshop.itsoso.cn/flow.php?step=checkout'
    submit.open_url(url)
    submit.click_sf()
